package com.farsunset.cim.sdk.server.slc.coder;

import com.farsunset.cim.constant.ChannelAttr;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.util.List;

@ChannelHandler.Sharable
public class WebTextMessageDecoder extends MessageToMessageDecoder<TextWebSocketFrame> {
    private final TextMessageDecoderDelegate textMessageDecoderDelegate = new TextMessageDecoderDelegate();

    @Override
    protected void decode(ChannelHandlerContext ctx, TextWebSocketFrame frame, List<Object> out) throws Exception {
        /*context.channel().attr(ChannelAttr.PING_COUNT).set(null);
        ByteBuf buffer = frame.content();
        byte type = buffer.readByte();
        if (CIMConstant.DATA_TYPE_PONG == type) {
            list.add(Pong.getInstance());
            return;
        }
        SentBody body = JSONUtils.fromJson(frame.text(), SentBody.class);
        list.add(body);*/
        ctx.channel().attr(ChannelAttr.PING_COUNT).set(null);
        String text = frame.text();
        textMessageDecoderDelegate.decoder(ctx, text, out);
    }

}
